package com.gxa.controller;

import com.alibaba.fastjson.JSONObject;

import com.gxa.dto.MsgDTO;
import com.gxa.service.SendMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/send")
public class PushMessageController {

    @Autowired
    private SendMessageService sendService;

    /**
     *
     * @param map 用户+消息  用户为空则为群发
     * @return String
     */
    @PostMapping("/sendToUser")
    public String sendToUser(@RequestBody Map<String, Object> map) {
        JSONObject param =new JSONObject(map);
        MsgDTO msgDTO = param.toJavaObject(MsgDTO.class);
        return sendService.send(msgDTO);
    }
}

